<template>
    首页
    <van-button type="success" @click=demo>成功按钮</van-button>
    <Tabbar />

</template>


<script setup>
const { proxy } = getCurrentInstance();

console.log(proxy.$demo.value);

const business = reactive({
    mobile: '15200000000',
    password: '111111',
});

import { showSuccessToast, showFailToast, showLoadingToast, showToast } from 'vant';



const demo = async () => {
    // 显示加载提示
    const loadingToast = showLoadingToast({
        message: '加载中...',
        forbidClick: true, // 禁用背景点击
        duration: 0 // 展示时长(ms)，值为 0 时，toast 不会消失，持续显示直到手动关闭
    });

    try {
        // 发送请求
        let result = await proxy.$http.post({
            url: '/business/login',
            params: business
        });

        // 关闭加载提示
        loadingToast.close();

        // 根据响应码展示相应的提示框
        if (result.code === 1) {
            showSuccessToast('登录成功');
            // 这里还需编写后续增加的操作
            console.log(result);
        } else {
            showToast({
                message: result.msg || '请求失败',
                icon: 'cross'
            });
        }
    } catch (error) {
        // 关闭加载提示并显示错误
        loadingToast.close();
        showFailToast(error.message || '网络错误');
        console.error('请求出错:', error);
    }
};
</script>